//
//  ViewController.m
//  AirLogClient
//
//  Created by Penghao on 14-1-8.
//  Copyright (c) 2014年 PengHao.
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#import "ViewController.h"
#include "AirGraphicsScene.h"
#include "AirLog.h"
#import "EAGLView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
//    [self performSelector:@selector(send:) withObject:nil afterDelay:0.5];
    
//    AirCpp::EnableSocketLog *log = AirCpp::AirSingleton<AirCpp::EnableSocketLog>::getInstance();
//    log->init((char *)"192.168.16.108", 8890);
    
//    AirCpp::AirSocketPackageWrite *wirter = NULL;
    
    EAGLView *glView = [[EAGLView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:glView];
    [glView startDrawing];
    
//    for (int i = 0; i <10000; ++i) {
//        AirCpp::AirInt32 rssi = i;
//        double distance = 2.0*rssi+1.0;
//        char beacon_id[100];
//        sprintf(beacon_id, "beacon_id_%d", i%2);
//        wirter = new AirCpp::AirSocketPackageWrite(2);
//        wirter->write_string(beacon_id);
//        wirter->write_data(rssi); //4
//        wirter->write_data(distance); //4
//        log->log(wirter);
//        release(wirter);
//        usleep(1000);
//    }
//    wirter = new AirCpp::AirSocketPackageWrite(3);
//    log->log(wirter);
//    release(wirter);
//    
//    
//    wirter = new AirCpp::AirSocketPackageWrite(-1);
//    log->log(wirter);
//    release(wirter);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    AirDebugLog("start Edting...");
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    AirDebugLog("end Edting!");
}

-(IBAction)send:(id)sender{
    while (true) {
        AirDebugLog("Received Msg: %s", self.textFeild.text.UTF8String);
        sleep(0.1);
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    if (![touch.view isKindOfClass:[UITextField class]]) {
        [self.textFeild resignFirstResponder];
    }
}
@end
